package dao

import (
	"context"
	"github.com/redis/go-redis/v9"
	"time"
)

type RedisCache struct {
	rdb *redis.Client
}

func New() *RedisCache {
	return &RedisCache{
		rdb: redis.NewClient(&redis.Options{
			Addr:     "192.168.65.220:6379",
			Password: "",
			DB:       0,
		}),
	}
}

func (c *RedisCache) Put(ctx context.Context, key, value string, expire time.Duration) error {
	err := c.rdb.Set(ctx, key, value, expire).Err()
	return err
}

func (c *RedisCache) Get(ctx context.Context, key string) (string, error) {
	result, err := c.rdb.Get(ctx, key).Result()
	return result, err
}
